package com.yfyszk.kingbird.controller;


import com.yfyszk.kingbird.common.utils.PageInfo;
import com.yfyszk.kingbird.common.utils.PageUtils;
import com.yfyszk.kingbird.common.utils.R;
import com.yfyszk.kingbird.feign.UserFeignClient;
import com.yfyszk.kingbird.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;


/**
 * test
 *
 * @author cx
 * @more   www.cx1314.cn
 * @date 2020-05-22 19:35:30
 */
@Slf4j
@RestController
@RequestMapping("test")
@Api("测试服务接口")
@CrossOrigin
public class TestController {
    @Autowired
    private ICouponService iCouponService;
    @Autowired
    private UserFeignClient userFeignClient;
    /**
     * 列表
     */
    @ApiOperation("测试服务list接口")
    @RequestMapping("/list")
    //@RequiresPermissions("coupon:coupon:list")
    public R list(@RequestParam Map<String, Object> params){
         String  result =  iCouponService.testFfeign();
         log.info("远程服务调用成功");
        return R.ok(result);
    }
    /**
     * 列表
     */
    @ApiOperation("测试服务testFeginClient接口")
    @RequestMapping("/testFeginClient")
    //@RequiresPermissions("coupon:coupon:list")
    public R String(String name){
        String  result =  iCouponService.testFfeign();
        log.info("远程服务调用成功");
        return R.ok(result);
    }
    @ApiOperation("测试服务listPage接口")
    @RequestMapping("/listPage")
    //@RequiresPermissions("coupon:coupon:list")
    public R listPage(@RequestParam Map<String, Object> params){
        PageUtils page = iCouponService.queryPage(params);

        return R.ok().put("page", page);
    }
    @RequestMapping("/listzdyPage")
    //@RequiresPermissions("coupon:coupon:list")
    public R listzdyPage(HttpServletRequest request, HttpServletResponse response, PageInfo pageInfo){
        PageUtils page = iCouponService.listzdyPage(pageInfo);

        return R.ok().put("page", page);
    }
    @GetMapping(value = "/userTestFeign")
    public R userTestFeign(HttpServletRequest request,String  name) {
        String user = userFeignClient.getUser(name);
        log.info("user:{}",user);
        return R.ok().setData(user);
    }
}
